//
//  HeadTableViewCell.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/26.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "HeadTableViewCell.h"

@interface HeadTableViewCell ()

@property (nonatomic, retain) UIButton *backButton;
@property (nonatomic, retain) UIImageView *dishImageView;
@property (nonatomic, retain) UIButton *playButton;
@property (nonatomic, retain) UIButton *preparePlayButton;
@property (nonatomic, retain) UILabel *prepareLabel;
@property (nonatomic, retain) UIButton *stepPlayButton;
@property (nonatomic, retain) UILabel *stepLabel;
@property (nonatomic, retain) UILabel *dishNameLabel;
@property (nonatomic, retain) UILabel *descriptionLabel;
@property (nonatomic, retain) UILabel *hardLevelLabel;
@property (nonatomic, retain) UILabel *cookTimeLabel;
@property (nonatomic, retain) UILabel *tasteLabel;


//渐变属性
@property (nonatomic, retain) UIView *layerView;
@property (nonatomic, retain) CAGradientLayer *gradientLayer;


@end
@implementation HeadTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //封面图片
        self.dishImageView = [[UIImageView alloc] init];
        self.dishImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.dishImageView.clipsToBounds = YES;
        [self.contentView addSubview:self.dishImageView];
        [_dishImageView release];
        
        
        //返回按钮
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.backButton setBackgroundImage:[UIImage imageNamed:@"back2"] forState:UIControlStateNormal];
        // 点击事件
        [self.backButton addTarget:self action:@selector(clickOnBackButton) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.backButton];
        [_backButton release];
        
        
        //播放按钮
        // 初始化
        self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.playButton];
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"iconfont-zhibo"] forState:UIControlStateNormal];
        // 点击事件
        [self.playButton addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
        
        // 食材准备标签
        self.prepareLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.prepareLabel];
        self.prepareLabel.text = @"食材准备";
        self.prepareLabel.textColor = [UIColor whiteColor];
        self.prepareLabel.font = [UIFont systemFontOfSize:15];
        [_prepareLabel release];
        
        
        //  步骤label
        self.stepLabel = [[UILabel alloc] init];
        self.stepLabel.text = @"制作步骤";
        self.stepLabel.textColor = [UIColor whiteColor];
        self.stepLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.stepLabel];
        [_stepLabel release];
        
        
        // dishNameLabel
        self.dishNameLabel  = [[UILabel alloc] init];
        [self.contentView addSubview:self.dishNameLabel];
        [_dishNameLabel release];
        
        //  descriptionLabel
        self.descriptionLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.descriptionLabel];
        self.descriptionLabel.numberOfLines = 0;
        self.descriptionLabel.font = [UIFont systemFontOfSize:15];
        self.descriptionLabel.textColor = [UIColor darkGrayColor];
        [self.descriptionLabel release];
        
        //  hardLevelLabel
        
        self.hardLevelLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.hardLevelLabel];
        self.hardLevelLabel.font = [UIFont systemFontOfSize:15];
        [self.hardLevelLabel release];
        
        //  cookTimeLabel
        self.cookTimeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.cookTimeLabel];
        self.cookTimeLabel.font = [UIFont systemFontOfSize:15];
        [_cookTimeLabel release];
        
        //  tasteLabel
        
        self.tasteLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.tasteLabel];
        self.tasteLabel.font = [UIFont systemFontOfSize:15];
        [self.tasteLabel release];
        
        //  渐变属性
        self.layerView = [[UIView alloc] init];
        self.gradientLayer = [CAGradientLayer layer];
        self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColor clearColor].CGColor,(id)[UIColor blackColor].CGColor, nil];
        self.gradientLayer.startPoint = CGPointMake(0.5, 0.5);
        self.gradientLayer.endPoint = CGPointMake(0.5, 1.0);
        
        [self.layerView.layer insertSublayer:self.gradientLayer atIndex:0];
        [self.dishImageView addSubview:self.layerView];
//
    }
    return self;
}

-(void)layoutSubviews
{
    // 调用父类布局方法
    [super layoutSubviews];
    self.backButton.frame = CGRectMake(20 * WIDTH  , 30 * WIDTH , WIDTH *375 * 0.08, WIDTH  * 375 *0.08);
    self.dishImageView.frame = CGRectMake(0, 0, WIDTH * 375, HEIGHT*667 * 0.7);
    
    self.playButton.frame = CGRectMake(WIDTH * 375 * 0.4, HEIGHT*667 * 0.7 * 0.4, WIDTH * 375 * 0.2, WIDTH * 375 * 0.2);
    self.preparePlayButton.frame = CGRectMake(WIDTH * 375 * 0.05, HEIGHT*667 * 0.65, WIDTH * 375 * 0.06, WIDTH * 375 * 0.06);
    self.prepareLabel.frame = CGRectMake(WIDTH * 375 * 0.11, HEIGHT*667 * 0.65, WIDTH * 375 * 0.2, WIDTH * 375 * 0.06);
    self.stepPlayButton.frame = CGRectMake(WIDTH * 375 * 0.4, HEIGHT*667 * 0.65, WIDTH * 375 * 0.06, WIDTH * 375 * 0.06);
    self.stepLabel.frame = CGRectMake(WIDTH * 375 * 0.46, HEIGHT*667 * 0.65, WIDTH * 375 * 0.2, WIDTH * 375 * 0.06);
    self.dishNameLabel.frame = CGRectMake(WIDTH * 375 * 0.1, HEIGHT*667 * 0.7, WIDTH * 375 * 0.8, HEIGHT*667 * 0.08);
    self.descriptionLabel.frame = CGRectMake(WIDTH * 375 * 0.1, HEIGHT*667 * 0.75, WIDTH * 375 * 0.8, HEIGHT*667 * 0.15);
    self.hardLevelLabel.frame = CGRectMake(WIDTH * 375 * 0.1, HEIGHT*667 * 0.9, WIDTH * 375 * 0.3, HEIGHT*667 * 0.1);
    self.cookTimeLabel.frame = CGRectMake(WIDTH * 375 * 0.35, HEIGHT*667 * 0.9, WIDTH * 375 * 0.4, HEIGHT*667 * 0.1);
    self.tasteLabel.frame = CGRectMake(WIDTH * 375 * 0.75, HEIGHT*667 * 0.9, WIDTH * 375 * 0.25, HEIGHT*667 * 0.1);
    self.layerView.frame = CGRectMake(0, self.dishImageView.frame.origin.y + self.dishImageView.frame.size.height - HEIGHT*667 * 0.15, self.dishImageView.frame.size.width * 375, HEIGHT*667 * 0.15);
    self.gradientLayer.bounds = self.layerView.bounds;
    self.gradientLayer.frame = self.layerView.bounds;
    

}
#pragma mark - 赋值
-(void)setF_model:(FoodModel *)f_model
{
    // retain类型赋值
    if (_f_model != f_model) {
        [_f_model release];
        _f_model = [f_model retain];
    }
    
    [self.dishImageView sd_setImageWithURL:[NSURL URLWithString:_f_model.image] placeholderImage:[UIImage imageNamed:@"jiazaitu"]];
    self.dishNameLabel.text = _f_model.dashes_name;
    self.descriptionLabel.text = _f_model.material_desc;
    self.hardLevelLabel.text = [NSString stringWithFormat:@"难度: %@", _f_model.hard_level];
    self.cookTimeLabel.text = [NSString stringWithFormat:@"烹饪时间: %@",_f_model.cooke_time];
    self.tasteLabel.text = [NSString stringWithFormat:@"口味: %@", _f_model.taste];
}


#pragma mark - 点击事件
- (void)clickOnBackButton
{
    //self.POPBLOCK();
}

- (void)playAction
{
   // self.PLAYBLOCK(self.f_model.process_video);
    self.play(self.f_model.process_video);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
